package com.yuqian.JavaSe.leetcode.easy;
/**
 * Given a column title as appear in an Excel sheet, return its corresponding column number.

For example:

    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28 
 * @author yuqian
 *其实这个问题可以看成是进制的转换问题 26进制向10进制转换
 */
public class ExcelSheetColumnNumber {
	//'A'的 ascii 值为65 'a' 为97
	 public int titleToNumber(String s) {
	        int sum=0;
	        if(s!=null&&!"".equals(s)){
	          int k=1;
	          char[] sc=s.toCharArray();
	          for(int i=sc.length-1;i>-1;i--){
	            sum +=k*(sc[i]-64);
	            k=k*26;
	          }
	        }
	        return sum;
	    }
}
